#
# Copyright 2014, NICTA
#
# This software may be distributed and modified according to the terms of
# the BSD 2-Clause license. Note that NO WARRANTY is provided.
# See "LICENSE_BSD2.txt" for details.
#
# @TAG(NICTA_BSD)
#

default: AutoCorresTest

all: AutoCorres AutoCorresTest AutoCorresSEL4 AutoCorresDoc

report-regression:
	@echo AutoCorres AutoCorresTest AutoCorresDoc AutoCorresSEL4

# Generate an Isabelle "ROOT" file containing all of our test cases.
tests/ROOT: \
		tests/parse-tests tests/examples \
		tests/parse-tests/*.c \
		$(patsubst %.c,%.thy,$(wildcard tests/parse-tests/*.c)) \
		tests/proof-tests/*.c \
		tests/proof-tests/*.thy \
		tests/examples/*.c \
		tests/examples/*.thy \
		../../misc/scripts/gen_isabelle_root.py
	python ../../misc/scripts/gen_isabelle_root.py -o $@ -b AutoCorres -s AutoCorresTest \
		-i tests/parse-tests -i tests/proof-tests -i tests/examples --quick-and-dirty

# Generate a Isabelle "All.thy" file containing imports to all the test cases.
tests/All.thy: \
		tests/parse-tests tests/examples \
		tests/parse-tests/*.c \
		$(patsubst %.c,%.thy,$(wildcard tests/parse-tests/*.c)) \
		tests/proof-tests/*.c \
		tests/proof-tests/*.thy \
		tests/examples/*.c \
		tests/examples/*.thy \
		../../misc/scripts/gen_isabelle_root.py
	python ../../misc/scripts/gen_isabelle_root.py -T -o $@ \
		-i tests/parse-tests -i tests/proof-tests -i tests/examples

# Generate a template ".thy" file from a ".c" file.
%.thy: %.c
	@echo "Generating '$@' from '$<'..."
	@printf '(* @LICENSE(NICTA) *)\n\n' > $@
	@printf 'theory %s\nimports "../../AutoCorres"\nbegin\n\n' $(notdir $(basename $<)) > $@
	@printf 'install_C_file "%s"\n\n' $(notdir $<) >> $@
	@printf 'autocorres "%s"\n\n' $(notdir $<) >> $@
	@printf 'end\n' >> $@

# Test all the files in our "tests/" directory.
AutoCorresTest: clean-tests tests/ROOT
	$(ISABELLE_TOOL) build -d ../.. -d tests -b -v AutoCorresTest
.PHONY: AutoCorresTest

# Parse the seL4 kernel
AutoCorresSEL4:
	make -C ../../proof CBaseRefine
	$(ISABELLE_TOOL) build -d ../.. -b -v AutoCorresSEL4
.PHONY: AutoCorresSEL4

# Build the documentation sub-sessions.
AutoCorresDoc:
	$(ISABELLE_TOOL) build -d ../.. -D doc/quickstart

# Clean out files generated by the test suite.
clean-tests:
	rm -f tests/parse-tests/*.thy
	rm -f tests/ROOT
.PHONY: clean-tests

clean: clean-tests

HEAPS := AutoCorres

include ../../misc/isa-common.mk

